package cbir;

import java.util.ArrayList;

public class Img {

	private static final float WEIGHT = 0.8f;
	private static final String cyborgPhp = "http://php.cyborg.s156.eatj.com/cyborg.php";
	
	private String name;
	private String thumbname;
	private String imgURL;
	private String thumbURL;
	private String originalURL;
	private String imageURI;
	private boolean isRemote;	// true if it's not in the local DB
	private int globalRank;
	private float textureScore;
	private float colorHistScore;
	private float colorDistScore;
	private float colorScore;
	private float similarityScore;
	private int height;
	private int width;
	private ArrayList<String> tags;

	
	public Img(float colorScore, String thumbname, String serverName, String contextPath){
		this.name = Thumb.getFilename(thumbname);
		this.thumbname = thumbname;
		this.imgURL = "http://" + serverName + contextPath + "/Cyborg/db/" + name;
		this.thumbURL = "http://" + serverName + contextPath + "/Cyborg/db/thumb/" + thumbname;
		this.originalURL = cyborgPhp + "?link=" + imgURL + "&title=" + name;
		this.imageURI = "local://"+name;
		this.isRemote = false;
		this.textureScore = 0.f;
		this.colorHistScore = 0.f;
		this.colorDistScore = 0.f;
		this.colorScore = colorScore;
		this.height = 0;
		this.width = 0;
		this.tags = new ArrayList<String>();
	}
	
	//	In QBE
	public Img(String thumbname, String serverName, String contextPath){
		this.name = Thumb.getFilename(thumbname);
		this.thumbname = thumbname;
		this.imgURL = "http://" + serverName + contextPath + "/Cyborg/db/" + name;
		this.thumbURL = "http://" + serverName + contextPath + "/Cyborg/db/thumb/"+thumbname;
		this.originalURL = cyborgPhp + "?link=" + imgURL + "&title=" + name;
		this.imageURI = "local://"+name;
		this.isRemote = false;
		this.textureScore = 0.f;
		this.colorHistScore = 0.f;
		this.colorDistScore = 0.f;
		this.colorScore = 0.f;
		this.height = 0;
		this.width = 0;
		this.tags = new ArrayList<String>();
	}

	// In QBT (local) and Random
	public Img(String name, String nada1, String nada2, String nada3, String serverName, String contextPath){
		this.name = name;
		this.thumbname = Thumb.getThumb(name);
		this.imgURL = "http://" + serverName + contextPath + "/Cyborg/db/" + name;
		this.thumbURL ="http://" + serverName + contextPath +"/Cyborg/db/thumb/" + thumbname;
		this.originalURL = cyborgPhp + "?link=" + imgURL + "&title=" + name;
		this.imageURI = "local://"+name;
		this.isRemote = false;
		this.textureScore = 0.f;
		this.colorHistScore = 0.f;
		this.colorDistScore = 0.f;
		this.colorScore = 0.f;
		this.height = 0;
		this.width = 0;
		this.tags = new ArrayList<String>();
	}
	
	// In QBT (remote)
	public Img(String name, String nada, String imgURL, String originalURL){
		this.name = name;
		this.thumbname = name;
		this.imgURL = imgURL;
		this.thumbURL = imgURL;
		this.originalURL = originalURL;
		this.imageURI = imgURL;
		this.isRemote = true;
		this.textureScore = 0.f;
		this.colorHistScore = 0.f;
		this.colorDistScore = 0.f;
		this.colorScore = 0.f;
		this.height = 0;
		this.width = 0;
		this.tags = new ArrayList<String>();
	}
	
	public Img(String thumbname, float colorScore, int height, int width){
		this.name = Thumb.getFilename(thumbname);
		this.thumbname = thumbname;
		this.imgURL = "";
		this.thumbURL = "";
		this.originalURL = "";
		this.imageURI = "";
		this.isRemote = false;
		this.textureScore = 0.f;
		this.colorHistScore = 0.f;
		this.colorDistScore = 0.f;
		this.colorScore = colorScore;
		this.height = height;
		this.width = width;
		this.tags = new ArrayList<String>();
	}
	
	// Flickr
	public Img(String name, String imgURL, String thumbURL, String originalURL, String imageURI, boolean isRemote) {
		super();
		this.name = name;
		this.thumbname = "";
		this.imgURL = imgURL;
		this.thumbURL = thumbURL;
		this.originalURL = originalURL;
		this.imageURI = imageURI;
		this.isRemote = isRemote;
		this.textureScore = 0.f;
		this.colorHistScore = 0.f;
		this.colorDistScore = 0.f;
		this.colorScore = 0.f;
		this.height = 0;
		this.width = 0;
		this.tags = new ArrayList<String>();
	}
	// Getters and Setters or other..
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getThumbname() {
		return thumbname;
	}
	public void setThumbname(String thumbname) {
		this.thumbname = thumbname;
	}
	public int getGlobalRank(){
		return globalRank;
	}
	public void setGlobalRank(int globalRank){
		this.globalRank = globalRank;
	}
	public float getTextureScore() {
		return textureScore;
	}
	public void setTextureScore(float textureScore) {
		this.textureScore = textureScore;
	}
	public float getColorHistScore() {
		return colorHistScore;
	}
	public void setColorHistScore(float colorHistScore) {
		this.colorHistScore = colorHistScore;
	}
	public float getColorDistScore() {
		return colorDistScore;
	}
	public void setColorDistScore(float colorDistScore) {
		this.colorDistScore = colorDistScore;
	}
	public float getColorScore() {
		return colorScore;
	}
	public void setColorScore() {
		this.colorScore = WEIGHT * colorDistScore + (1 - WEIGHT) * colorHistScore;
	}
	public float getSimilarityScore() {
		return similarityScore;
	}
	public void setSimilarityScore() {
		this.similarityScore = (float) ( Math.sqrt( Math.pow(colorScore, 2.) + Math.pow(textureScore, 2.) ) / Math.sqrt(2.) );
	}
	public int getHeight() {
		return height;
	}
	public void setHeight(int height) {
		this.height = height;
	}
	public int getWidth() {
		return width;
	}
	public void setWidth(int width) {
		this.width = width;
	}
	public ArrayList<String> getTags() {
		return tags;
	}
	public void setTags(ArrayList<String> tags) {
		this.tags = tags;
	}
	public void addTag(String tag){
		this.tags.add(tag);
	}

	public String getImgURL() {
		return imgURL;
	}

	public void setImgURL(String imgURL) {
		this.imgURL = imgURL;
	}

	public String getThumbURL() {
		return thumbURL;
	}

	public void setThumbURL(String thumbURL) {
		this.thumbURL = thumbURL;
	}

	public String getOriginalURL() {
		return originalURL;
	}

	public void setOriginalURL(String originalURL) {
		this.originalURL = originalURL;
	}

	public void setRemote(boolean isRemote) {
		this.isRemote = isRemote;
	}

	public boolean isRemote() {
		return isRemote;
	}

	public void setImageURI(String imageURI) {
		this.imageURI = imageURI;
	}

	public String getImageURI() {
		return imageURI;
	}

}